package com.hyjr.RxTask.work;

import java.util.Date;

import com.alibaba.fastjson.JSON;
import com.hyjr.RxTask.rabbitmq.ProducerUtil;
import com.hyjr.RxTask.rabbitmq.RabbitmqConstants;
import com.hyjr.RxTask.work.service.ConsumerWork;
import com.hyjr.bean.CheckBean;
import com.hyjr.common.enums.CheckStateEnum;
import com.hyjr.common.enums.StrengthLevelEnum;
import com.hyjr.common.utils.LogUtils;

public class MiddleCheckWork implements ConsumerWork {
	private static MiddleCheckWork _dctaskScheduler = null;

	public static MiddleCheckWork GetInstance() {
		if (_dctaskScheduler == null) {
			_dctaskScheduler = new MiddleCheckWork();
		}
		return _dctaskScheduler;
	}

	@Override
	public void doWork(String message) throws Exception {
		LogUtils.debug("检测端，MiddleCheckWork线程，消费数据：" + message);
		
		CheckBean checkBean = JSON.parseObject(message, CheckBean.class);
		checkBean.setStartCheckTime(new Date());
		
		//执行破解操作
		Thread.sleep(10000);
		
		//检测结果
		checkBean.setCheckState(CheckStateEnum.FINISHED.getKey());
		checkBean.setEndCheckTime(new Date());
		checkBean.setStrengthLevel(StrengthLevelEnum.RISK_PWD.getKey());
		
		//将检测结果放入检测结果队列中
		ProducerUtil.producer(RabbitmqConstants.CHECK_RESULT, checkBean);
		LogUtils.debug("检测端，MiddleCheckWork线程，将检测数据结果放入队列中，数据结果：" + message);
	}
}
